<?php

Raise::load('control.RaiseProgressBar');

/**
 * TestContolRaiseProgressBar class
 * Testing unit of 'phpraise/control/RaiseProgressBar.php'
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.UnitTest.Test
 */
class TestControlRaiseProgressBar extends RaiseTest {

    public static function testClass(){
        self::assertClassExists('RaiseProgressBar');
        self::assertClassExtends('RaiseProgressBar', 'RaiseUIControl');
    }

    public static function testProgressBarLegacy(){
        $bar = new RaiseProgressBar(50, 100);
        $bar->useHTML5(false);
        $bar->size(100, 20);
        $bar->clientId('test');

        $tree = RaiseDomParser::parseString($bar->output());
        $tag = $tree->children()->get(0)->tag();
        self::assertStrictEqual($tag->tagName(), 'div');
        self::assertStrictEqual($tag->attributes()->get('id'), 'test');
        self::assertStrictEqual($tree->children()->get(0)->children()->get(0)->tag()->attributes()->count(), 2);
        self::assertTrue($tag->attributes()->keyExists('style'));        
    }

    public static function testProgressBarHtml5(){
        $bar = new RaiseProgressBar(50, 100);
        $bar->useHTML5(true);
        $bar->size(100, 20);
        $bar->clientId('test');

        self::assertObjectClass($bar, 'RaiseProgressBar');

        $tree = RaiseDomParser::parseString($bar->output());
        
        $tag = $tree->children()->get(0)->tag();
        self::assertStrictEqual($tag->tagName(), 'progress');
        self::assertStrictEqual($tag->attributes()->get('id'), 'test');
        self::assertStrictEqual($tag->attributes()->get('max'), '100');
        self::assertStrictEqual($tag->attributes()->get('value'), '50');
        self::assertTrue($tag->attributes()->keyExists('style'));
    }
}

